Skip to content

Add a structural Version to Archetype for cheap change detection - #310

Open
lgarczyn wants to merge 1 commit into
genaray:masterfrom
lgarczyn:archetype-structural-version
Open

Add a structural Version to Archetype for cheap change detection#310
lgarczyn wants to merge 1 commit into
genaray:masterfrom
lgarczyn:archetype-structural-version

Conversation

@lgarczyn

Copy link
Copy Markdown

Version is a monotonic counter that advances whenever entities enter or leave an archetype, at every EntityCount mutation site: Add, AddAll, Remove, Clear and Copy.

It lets a query detect structural change by folding the Version of its matched archetypes, O(archetypes), instead of hashing every entity id, O(entities). Unchanged folds guarantee unchanged membership. A same-count remove-then-add swap still advances the Version, which an EntityCount comparison alone would miss.

Version is a monotonic counter that advances whenever an entity enters or
leaves an archetype. It is advanced inside the EntityCount setter, the only
way to change the count, so every add, remove, move, clear and bulk restore
path advances it with no way to bypass, the Dangerous serialization
extensions included.

It lets a query detect structural change by comparing the Version of its
matched archetypes, O(archetypes), instead of hashing every entity id,
O(entities). Unchanged versions guarantee unchanged membership. A same-count
remove-then-add swap still advances the Version, which an EntityCount
comparison alone would miss.
@lgarczyn
lgarczyn force-pushed the archetype-structural-version branch from 364db03 to 1a5ad40 Compare July 16, 2026 01:12
@genaray

genaray commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Looks, good. Thanks! Im about to merge this :) do you any Idea what other Features can ne build on top of this? Just for the Future? ^^

@lgarczyn

Copy link
Copy Markdown
Author

Looks, good. Thanks! Im about to merge this :) do you any Idea what other Features can ne build on top of this? Just for the Future? ^^

For me it's just the ability to gate systems on if new entities died or appeared, I want to build a dumb class tbat stores the previous versions of every archetype in a query, and return a bool if the version changed on any of them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants